layui.use(['table', 'ztree', 'code'], function () {
    DGG.loading();
    var table = layui.table;
    var ztree = layui.ztree;
    layui.code(); //引用code方法
    pageSearch();// 默认
    DGG.loading("close");
    /**
     * 监听工具条
     */
    table.on('tool(dataTableFilter)', function (obj) {
        var data = obj.data;
        if (obj.event === 'receiveOrder') {
            receiveOrder(data.id);
        }
    });

    $(document).on('keydown', function (e) {  //document为当前元素，限制范围，如果不限制的话会一直有事件
        if (e.keyCode == 13) {
            pageSearch();
        }
    })
});

var table = layui.table;

// 查询
function pageSearch() {
    var params = $("#searchForm").serializeObject();
    table.render({
        elem: '#userTable',
        url: '/receiveOrder/queryPage.do',
        where: params,
        page: true,
        id: "userTable",
        text: {none: '暂无数据'},
        cols: [[
            {checkbox: true, fixed: true},
            {field: 'scOrderNo', title: '订单编号',},
            {field: 'customerName', title: '客户'},
            {field: 'businessTypeName', title: '业务类型'},
            {field: 'productNames', title: '订单商品'},
            {field: 'signDate', title: '签单时间'},
            {field: 'signUserName', title: '签单商务'},
            {field: 'signUserOrgName', title: '签单部门'},
            {field: "payMethod", title: '订单类型'},
            {title: "操作", toolbar: '#dataTableFilter'}
        ]]
    });
}


function receiveOrder(id) {
    DGG.confire("确认接单吗？", function () {
        $.ajax({
            url: sysInfo.basePath + "/receiveOrder/receiveOrder.do",
            data: {id: id},
            type: "POST",
            dataType: "json",
            success: function (obj) {
                if (obj.success == false) {
                    layer.msg(obj.msg);
                } else {
                    layer.msg("保存成功！");
                    table.reload("userTable");
                }
            }
        });
    });


}